#include "pch.h"
#include "DataTypes.h"

namespace LoadingWK
{

    EquipmentClr::EquipmentClr():
        _id(-1),
        _gravityY(0.0),
        _weight(0.0)
    {
        _axleLoadList = gcnew Generic::List<AxleLoadClr^>(0);
        _adaptedAirplaneTypeIDs = gcnew Generic::List<Int32>(0);
    }

    EquipmentClr::EquipmentClr(Int32 id):
        _id(id),
        _gravityY(0.0),
        _weight(0.0)
    {
        _axleLoadList = gcnew Generic::List<AxleLoadClr^>(0);
        _adaptedAirplaneTypeIDs = gcnew Generic::List<Int32>(0);
    }

    bool EquipmentClr::addAxleLoad(AxleLoadClr ^ axleLoad)
    {
        if (axleLoad == nullptr){   return false;}

        _axleLoadList->Add(axleLoad);
        return true;
    }

    LoadedEquipmentListClr::LoadedEquipmentListClr()
    {
        _loadedEquipmentList = gcnew Generic::List<LoadedEquipmentClr^>(0);
    }


    bool LoadedEquipmentListClr::addEquipment(LoadedEquipmentClr^ loadedEquipment)
    {
        if (loadedEquipment == nullptr) { return false; }
        _loadedEquipmentList->Add(loadedEquipment);
        return true;
    }
    
    int LoadedEquipmentListClr::getCountOfLoadedAirplane()
    {
        
        int count = 0;
        Generic::List<LoadedAirplaneIDClr^>^ airplaneIDs = gcnew Generic::List<LoadedAirplaneIDClr ^>(0);
        for (int i = 0 ; i < _loadedEquipmentList->Count ; i++)
        {
            LoadedAirplaneIDClr^ curAirID = gcnew LoadedAirplaneIDClr();
            curAirID->_indexID = _loadedEquipmentList[i]->_indexOfLoadedAirplane;
            curAirID->_typeID = _loadedEquipmentList[i]->_typeIDOfAirplane;

            int index = -1/*= airplaneIDs->FindIndex(airID->sameAirplane)*/;
            for (int j = 0; j < airplaneIDs->Count ; j++)
            {
                if (curAirID->sameAirplane(airplaneIDs[j]))
                {
                    index = j;
                    break;
                }
            }
            if (index < 0)
            {
                airplaneIDs->Add(curAirID);
            }
        }
        return airplaneIDs->Count;
    }

    AirplaneClr::AirplaneClr() :
        _typeID(-1),
        _gravityY(0.0), 
        _minY(0.0),_maxY(0.0),
        _weight(0.0),
        _locationTypeOfStartLoading(0)
    {
        _weightLimitOfAreaList = gcnew Generic::List<WeightLimitClr^>(0);
        _tag = gcnew String("");
    }

    AirplaneClr::AirplaneClr(Int32 typeID):
        _typeID(typeID),
        _gravityY(0.0),
        _minY(0.0), _maxY(0.0),
        _weight(0.0),
        _locationTypeOfStartLoading(0)
    {
        _weightLimitOfAreaList = gcnew Generic::List<WeightLimitClr^>(0);
        _tag = gcnew String("");
    }

    bool AirplaneClr::addWeightLimit(WeightLimitClr^ weightLimit)
    {
        if (weightLimit == nullptr) { return false; }

        _weightLimitOfAreaList->Add(weightLimit);
        return true;
    }
    
    bool LoadedAirplaneIDClr::sameAirplane(LoadedAirplaneIDClr^ loadedAirplane)
    {
        if (loadedAirplane == nullptr){   return false;}
        if (loadedAirplane->_typeID == _typeID && 
            loadedAirplane->_indexID == _indexID)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    LoadedAirplaneClr::LoadedAirplaneClr(): 
        AirplaneClr(), _loadedIndex(-1) 
    {
        _loadedEquipments = gcnew Generic::List<LoadedEquipmentClr ^>(0);
    }
    LoadedAirplaneClr::LoadedAirplaneClr(Int32 index, Int32 typeID) :
        AirplaneClr(typeID), _loadedIndex(index)
    {
        _loadedEquipments = gcnew Generic::List<LoadedEquipmentClr ^>(0);
    }
}